package com.atguigu.business.service.impl;

import com.atguigu.business.feign.OrderFeignClient;
import com.atguigu.business.feign.StrorageFeignClient;
import com.atguigu.business.service.BusinessService;
import org.apache.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private StrorageFeignClient strorageFeignClient;

    @Autowired
    private OrderFeignClient orderFeignClient;
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    //全局事务路口,表明这个方法是一个全局事务TM,其他调用模块为RM分支事务
    public void purchase(String userId, String commodityCode, int orderCount) {
        //TODO 1. 扣减库存
  strorageFeignClient.deduct(commodityCode, orderCount);
        //TODO 2. 创建订单
        orderFeignClient.create(userId,commodityCode,orderCount);
    }
}
